package cn.etouch.huangli;

import java.sql.*;

public class ConnectionUtil {
	static int conCount = 0;
	public static void main(String[] args) throws SQLException {
		Connection con = ConnectionUtil.getInstance().getConnection();
		Statement s = con.createStatement();
//		ResultSet rs = s.executeQuery("select * from huangli");
		int i =s.executeUpdate("INSERT INTO `huangli`.`huangli` (`day`, `value`) VALUES ('20110201', 'dfsadsa');");
//		if (rs != null) {
//			rs.next();
//			System.out.println("result find");
//		}
		System.out.println(""+i);
	}
	
	private static int flag = 0;

	static ConnectionUtil instance;

	public static ConnectionUtil getInstance() {
		if (instance == null)
			instance = new ConnectionUtil();
		return instance;
	}

	private ConnectionUtil() {
		if (flag == 0) {
			// init();
		}
	}

	private Connection getConnectionFromDatabase() {
		Connection trueConn = null;
		try {

			Class.forName("com.mysql.jdbc.Driver");
			String url = "jdbc:mysql://localhost:3306/huangli?user=root&password=root&useUnicode=true&characterEncoding=utf-8";

			trueConn = DriverManager.getConnection(url);
		} catch (Exception ex) {
			ex.printStackTrace();
			System.out.println("sql exception" + ex.toString());
		}
		conCount++;
		return trueConn;
	}

	public Connection getConnection() {
		return getConnectionFromDatabase();
	}

	public boolean release(Connection conn) {
		if (conn != null) {
			try {
				conn.close();
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			conn = null;
		}
		return true;
	}

}